package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResOrder;
import com.ruoyi.system.service.IResOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆订单Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/system/resorder")
public class ResOrderController extends BaseController
{
    @Autowired
    private IResOrderService resOrderService;

    /**
     * 查询餐馆订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:resorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResOrder resOrder)
    {
        startPage();
        List<ResOrder> list = resOrderService.selectResOrderList(resOrder);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('system:resorder:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(ResOrder resOrder)
    {
        startPage();
        List<ResOrder> list = resOrderService.selectResOrderList1(resOrder);
        return getDataTable(list);
    }

    /**
     * 导出餐馆订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:resorder:export')")
    @Log(title = "餐馆订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResOrder resOrder)
    {
        List<ResOrder> list = resOrderService.selectResOrderList(resOrder);
        ExcelUtil<ResOrder> util = new ExcelUtil<ResOrder>(ResOrder.class);
        util.exportExcel(response, list, "餐馆订单数据");
    }

    /**
     * 获取餐馆订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resorder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(resOrderService.selectResOrderByOrderId(orderId));
    }

    /**
     * 新增餐馆订单
     */
//    @PreAuthorize("@ss.hasPermi('system:resorder:add')")
    @Log(title = "餐馆订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ResOrder resOrder)
    {
        return toAjax(resOrderService.insertResOrder(resOrder));
    }

    /**
     * 修改餐馆订单
     */
    @PreAuthorize("@ss.hasPermi('system:resorder:edit')")
    @Log(title = "餐馆订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResOrder resOrder)
    {
        return toAjax(resOrderService.updateResOrder(resOrder));
    }

    /**
     * 删除餐馆订单
     */
    @PreAuthorize("@ss.hasPermi('system:resorder:remove')")
    @Log(title = "餐馆订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(resOrderService.deleteResOrderByOrderIds(orderIds));
    }
}
